#include <iostream>
using namespace std;
const int N = 5e3 + 7;
int n;
int a[N];
int q[N];
int l[N],r[N];

int main()
{
  // 请在此输入您的代码
  cin >> n;
  for(int i = 1;i <= n;i++)
  {
    cin >> a[i];
  }
  int top = 0;
  for(int i = 1;i <= n;i++)
  {
    while(top && a[i] <= a[q[top]])
    {
      top--;
    }
    l[i] = q[top];
    q[++top] = i;
  }
  top = 0;
  for(int i = n;i >= 0;i--)
  {
    while(top && a[i] <= a[q[top]])
    {
      top--;
    }
    r[i] = q[top];
    q[++top] = i;
  }
  int ans = 0;
  for(int i = 1;i <= n;i++)
  {
    ans = max(ans,a[i] * ((r[i] - 1) - (l[i] + 1) + 1));
  }
  cout << ans << endl;
  return 0;
}